package com.li.day.day17;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Delete extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("gbk");
        resp.setContentType("type/html;charset=utf-8");
        Connection co=null;
        PreparedStatement pp=null;
        Object name3 = req.getSession().getAttribute("name3");
        String s = "DELETE FROM ppro where user_name='" + name3 + "'";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
             co = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/p3kao", "root", "root");
             pp = co.prepareStatement(s);
            int i = pp.executeUpdate();
            if (i>0){
                resp.getWriter().write("注销成功");
                req.getRequestDispatcher("Denglu").forward(req,resp);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
